package com.inkyi.assistant.app.todolist.left;

import com.inkyi.assistant.app.todolist.TodoContext;
import com.inkyi.framework.daqian.share.jlist.PkListModel;

import javax.swing.*;
import java.awt.*;
import java.io.Serializable;

public class GroupItem extends JPanel implements PkListModel {
    /**
     * ID
     */
    private Serializable id;
    /**
     * 图标
     */
    private Icon icon;
    /**
     * 标题
     */
    private String title;
    /**
     * 标题标签
     */
    private JLabel titleLabel;


    @Override
    public Serializable getPk() {
        return id;
    }

    public GroupItem(Serializable id, String title) {
        this.id = id;
        this.title = title;
        initComponents();
    }

    public GroupItem(Serializable id, String title, Icon icon) {
        this.id = id;
        this.title = title;
        this.icon = icon;
        initComponents();
    }

    private void initComponents() {
        this.setPreferredSize(new Dimension(100, 28));
        this.setBorder(BorderFactory.createEmptyBorder(1, 0, 1, 0));
        this.setLayout(new CardLayout());
        if (icon == null) {
            icon = TodoContext.GROUP_ICOM_DEF;
        }
        titleLabel = new JLabel(title, icon, SwingConstants.LEADING);
        titleLabel.setIconTextGap(10);
        this.add(titleLabel);

    }

    public Serializable getId() {
        return id;
    }

    public void setId(Serializable id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
        titleLabel.setText(title);
    }

    public Icon getIcon() {
        return icon;
    }

    public void setIcon(Icon icon) {
        this.icon = icon;
    }
}
